package main

import (
	"database/sql"
	"fgo/advance/db/gorm2/models"
	"time"
)

func main() {
	db := models.NewDb()

	users := models.User{
		Birthday: time.Now(),
		Age:      20,
		Name:     "ZoneName",
		//Num:               20,
		CreditCard: models.CreditCard{
			Number: "3713211xxxxx",
		},
		Emails: []models.Email{
			{Email: "121212@qq.com", Subscribed: false},
			{Email: "121212@qq.com", Subscribed: false},
			{Email: "121212@qq.com", Subscribed: false},
		},
		BillingAddress:    models.Address{
			Address1: "add11",
			Address2: "add11",
			Post: sql.NullString{String: "content",Valid: true},
		},
		//BillingAddressID:  sql.NullInt64{},
		ShippingAddress:   models.Address{
			Address1: "add22",
			Address2: "add22",
			Post: sql.NullString{String: "content",Valid: true},
		},
		//ShippingAddressID: 0,
		IgnoreMe:          99999,
		Languages:         []models.Language {
			{Name: "CN", Code: "100000"},
			{Name: "JP", Code: "100001"},
		},
		Orders: []models.Order {
			{Price:  100},
		},
	}
	// 跳过自动创建
	// 错误
	// db.Omit("CreditCards").Omit("CreditCard").Create(&users)
	// 正确
	//db.Omit("CreditCard").Create(&users)
	db.Create(&users)

}
